package com.dfz.aliyun.design.pattern.c16.chainofresponsibility;

public abstract class AbstractLogger {
    public static int INFO = 1;
    public static int DEBUG = 2;
    public static int ERROR = 3;

    protected int level;

    protected AbstractLogger nextLogger;

    /**
     * 获取下一级日志处理器
     * @param nextLogger 下一级日志
     */
    public void setNextLogger(AbstractLogger nextLogger) {
        this.nextLogger = nextLogger;
    }

    /**
     * 记录日志
     * @param level    日志级别
     * @param message  日志内容
     */
    public void logMessage(int level, String message) {
        if (this.level <= level) {
            write(message);
        }
        if (null != nextLogger) {
            nextLogger.logMessage(level, message);
        }
    }

    protected abstract void write(String message);
}
